Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contains operator #99

Merged
merged 46 commits into from
Feb 27, 2025
Merged

contains operator #99

merged 46 commits into from
Feb 27, 2025

Conversation

diana-qing
Copy link
Contributor

@diana-qing diana-qing commented Feb 19, 2025

This PR implements support for a contains operator that can be used with strings or bytes. When used with bytes, the protocol field of the filter can be a string or a byte (if it's a string, it gets converted to a byte before comparison is done).

//! | `<` | `lt` | Less than | `ipv6.payload_length < 500` |
//! | `in` | | In a range, or in a subnet | `ipv4.src_addr in 1.2.3.4/16` |
//! | `~` | `matches` | Regular expression match | `tls.sni ~ 'netflix\\.com$'` |
//! | Operator | Alias | Description | Example |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge deal, but do you know what changed here to cause this diff? Seems like there shouldn't actually be a change here.

//! | `<` | `lt` | Less than | `ipv6.payload_length < 500` |
//! | `in` | | In a range, or in a subnet | `ipv4.src_addr in 1.2.3.4/16` |
//! | `~` | `matches` | Regular expression match | `tls.sni ~ 'netflix\\.com$'` |
//! | `contains` | | Check if right appears in left | `tls.sni contains \|2E 63 6F 6D\|` |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the \ required to indicate bytes?

let bytes_lit = syn::LitByteStr::new(b, Span::call_site());
let num_bytes = bytes_lit.value().len();
quote! {
#proto.#field().as_bytes().windows(#num_bytes).any(|w| w == #bytes_lit)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that we talked about this and I said windows seemed like a good idea, but I just found the following crates that look like they would be more efficient. I think these would work for both strings and bytes.

Could you do a bit of research into these and figure out which one makes the most sense? I don't know that we have to go into depth profiling them, but worth taking a look.

@thearossman thearossman merged commit d897702 into stanford-esrg:main Feb 27, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants